<script setup>
import SltFromOthApi from '@/components/SltFromOthApi/SltFromOthApi.vue'
import {
  PlusOutlined,
  SearchOutlined,
  RedoOutlined,
  VerticalAlignBottomOutlined
} from '@ant-design/icons-vue'
import { getOptions } from '@/utils'
import { ref } from 'vue'

const emits = defineEmits(['add', 'init', 'search', 'exportToExcel'])

// 新增按钮点击
const add = () => {
  emits('add')
}
//数据导出
const exportToExcel = () => {
  emits('exportToExcel')
}
// 刷新
const orderNo = ref('')
const machineId = ref(null)
const machineType = ref(null)
const orderStatus = ref(null)
const init = () => {
  orderNo.value = ''
  machineId.value = null
  machineType.value = null
  orderStatus.value = null
  emits('init')
}
// 搜索
const search = () => {
  emits('search', {
    orderNo: orderNo.value ?? null,
    machineType: machineType.value ?? null,
    orderStatus: orderStatus.value ?? null,
    machineId: machineId.value?.[machineId?.value?.length - 1] || null
  })
}
</script>

<template>
  <div class="head">
    <div>
      <AButton class="button" type="primary" @click="add"> <PlusOutlined /> 新增 </AButton>
      <AButton type="primary" @click="exportToExcel">
        <VerticalAlignBottomOutlined /> 导出
      </AButton>
    </div>
    <div class="right">
      <a-select
        @change="search"
        class="com-ipt"
        placeholder="筛选农机类型"
        v-model:value="machineType"
        :options="getOptions('machine_type')"
        allowClear
        :fieldNames="{ label: 'constLabel', value: 'constValue' }"
      />
      <a-select
        @change="search"
        class="com-ipt"
        placeholder="筛选工单状态"
        v-model:value="orderStatus"
        :options="getOptions('order_status1')"
        allowClear
        :fieldNames="{ label: 'constLabel', value: 'constValue' }"
      />
      <SltFromOthApi
        @change="search"
        :fieldNames="{ label: 'machineName', value: 'machineId', children: 'children' }"
        v-model="machineId"
        placeholder="请选择农机查询"
        :dataProp="['data', 'records']"
        apiName="getMachinList"
        class="com-ipt"
        :params="{ size: 9999 }"
      />
      <AButton type="primary" @click="search"> <SearchOutlined /> 搜索 </AButton>
      <AButton type="primary" @click="init"> <RedoOutlined /> 刷新 </AButton>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.head {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  .button {
    margin-right: 10px;
  }
  .right {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
}
</style>
